﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using BarCode.Common;
using BarCode.AccessDao;
using BarCode.Bean;

namespace BarCode.Forms
{
    public partial class Config : Form
    {
        public Config()
        {
            InitializeComponent();
        }

        private void Config_Load(object sender, EventArgs e)
        {
            if (GlobalVal.bolNetConnect)
            {
                DB01Dao db01 = new DB01Dao(GlobalVal.ipAddressInfo.SERVICE_IP, GlobalVal.serverMysqlInfo.USERID, GlobalVal.serverMysqlInfo.USERPWD);
                List<LineInfo> lstLine = db01.getLineInfo();
                if (lstLine.Count > 0)
                {
                    cmbLineNo.DataSource = lstLine;
                    cmbLineNo.DisplayMember = "disName";
                    cmbLineNo.ValueMember = "lineNo";
                }
                else
                {
                    cmbLineNo.Items.Clear();
                }
            }
            // 显示初始信息
            txtServerIp.Text = GlobalVal.ipAddressInfo.SERVICE_IP;
            txtPrinter.Text = GlobalVal.ipAddressInfo.PRINTER_NAME;
            txtDbName.Text = GlobalVal.ipAddressInfo.DATABASE_NAME;
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        /// <summary>
        /// 保存处理
        /// </summary>
        private void btnSave_Click(object sender, EventArgs e)
        {
            ConfigMdbDao configMdbDao = new ConfigMdbDao();
            object selectedObj = cmbLineNo.SelectedItem;
            if (selectedObj != null)
            {
                LineInfo selectedLineNo = (LineInfo)selectedObj;
                configMdbDao.saveLineInfo(selectedLineNo);
            }

            // 保存IP地址、打印机名称和数据库名称
            configMdbDao.saveConfigInfo(txtServerIp.Text, txtPrinter.Text, txtDbName.Text);
        }
    }
}
